package org.springblade.modules.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import liquibase.pro.packaged.B;
import lombok.AllArgsConstructor;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.admin.entity.MaintainScoreIssue;
import org.springblade.modules.admin.service.MaintainScoreIssueService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Date 10:36 2025/4/9
 * @Description {
 *   评分问题
 * }
 * @Author lsay
 **/
@AllArgsConstructor
@RestController
@RequestMapping("/maintain/score/issue")
public class MaintainScoreIssueController {

	private final MaintainScoreIssueService scoreIssueService;

	/**
	 * @Author lsay
	 * @Description {
	 *   分页查询
	 * }
	 * @Date 10:44 2025/4/9
	 * @Param
	 * @return 分页列表
	 **/
	@GetMapping("/page")
	public R<IPage<MaintainScoreIssue>> selectPage(Query query){
		query.setDescs("create_time");
		return R.data(scoreIssueService.page(Condition.getPage(query)));
	}

	/**
	 * @Author lsay
	 * @Description {
	 *   列表查询
	 * }
	 * @Date 10:44 2025/4/9
	 * @Param
	 * @return 列表查询
	 **/
	@GetMapping("/list")
	public R<List<MaintainScoreIssue>> selectList(String keyword){
		List<MaintainScoreIssue> list;
		if(Func.isNotEmpty(keyword)){
			list = scoreIssueService.list(Wrappers.<MaintainScoreIssue>lambdaQuery().like(MaintainScoreIssue::getIssueDesc,keyword));
		}else {
			list = scoreIssueService.list();
		}
		return R.data(list);
	}

	/**
	 * @Author lsay
	 * @Description {
	 *   新增或修改
	 * }
	 * @Date 10:45 2025/4/9
	 * @Param
	 * @return 成功与否
	 **/
	@PostMapping("/submit")
	public R<Boolean> submit(@RequestBody MaintainScoreIssue scoreIssue){
		return R.data(scoreIssueService.saveOrUpdate(scoreIssue));
	}

	/**
	 * @Author lsay
	 * @Description {
	 *   逻辑删除
	 * }
	 * @Date 10:47 2025/4/9
	 * @Param id集合字符串 逗号隔开
	 * @return 成功与否
	 **/
	@DeleteMapping("/remove")
	public R<Boolean> remove(String ids){
		return R.data(scoreIssueService.removeByIds(Func.toLongList(ids)));
	}

}
